#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//从键盘读取数据，写入管道，读取管道，写到屏幕上
int main(void)
{
  int fds[2];//pipe的俩端口
  char buf[100];//缓冲区
  int len;

  if(pipe(fds) == -1)
    perror("make pipe"),exit(1);

  //从屏幕读取
  while(fgets(buf,100,stdin))
  {
    len = strlen(buf);
    //写到管道里
    if(write(fds[1],buf,len)!= len)
    {
      perror("write to pipe");
      break;
    }
    memset(buf,0x00,sizeof(buf));

    //从管道里面读取
    if((len=read(fds[0],buf,100)) == -1)
    {
      perror("read from pipe");
      break;
  }
    //写到屏幕上
    if(write(1,buf,len)!=len)
    {
      perror("write to stdout");
      break;
    }
  }


}
